소스 검색

cicd: fix tests

jamesread 2 년 전
부모
커밋
fbbf168e88
2개의 변경된 파일28개의 추가작업 그리고 23개의 파일을 삭제
  1. 1 1
      internal/grpcapi/grpcApiActions.go
  2. 27 22
      internal/httpservers/restapi_test.go

+ 1 - 1
internal/grpcapi/grpcApiActions.go

@@ -119,7 +119,7 @@ func buildChoices(choices []config.ActionArgumentChoice) []*pb.ActionArgumentCho
 
 
 func createPublicID(action *config.Action, entityPrefix string) string {
 func createPublicID(action *config.Action, entityPrefix string) string {
 	h := sha256.New()
 	h := sha256.New()
-	h.Write([]byte(action.ID+"."+entityPrefix))
+	h.Write([]byte(action.ID + "." + entityPrefix))
 
 
 	return fmt.Sprintf("%x", h.Sum(nil))
 	return fmt.Sprintf("%x", h.Sum(nil))
 }
 }

+ 27 - 22
internal/httpservers/restapi_test.go

@@ -86,28 +86,7 @@ func testBase(t *testing.T, expire int64, expectCode int) {
 	})
 	})
 
 
 	// make server and attach handler
 	// make server and attach handler
-	srv := &http.Server{Handler: cors.AllowCors(mux)}
-	lis, _ := net.Listen("tcp", ":1337")
-
-	/*
-		if err != nil {
-			t.Errorf("Could not listen %v", err)
-		}
-
-			if srv == nil {
-				y.Errorf("srv is nil. Could not listen %v", err)
-			}
-	*/
-
-	go func() {
-		if lis == nil {
-			t.Errorf("couldn't start server: listener is null")
-		} else {
-			if err := srv.Serve(lis); err != nil {
-				t.Errorf("couldn't start server: %v", err)
-			}
-		}
-	}()
+	setupTestingServer(mux, t)
 
 
 	// make http client and send request to myself
 	// make http client and send request to myself
 	client := &http.Client{}
 	client := &http.Client{}
@@ -130,6 +109,32 @@ func testBase(t *testing.T, expire int64, expectCode int) {
 	}
 	}
 }
 }
 
 
+func setupTestingServer(mux *runtime.ServeMux, t *testing.T) {
+	lis, err := net.Listen("tcp", ":1337")
+
+	if err != nil || lis == nil {
+		t.Errorf("Could not listen %v %v", err, lis)
+		return
+	}
+
+	srv := &http.Server{Handler: cors.AllowCors(mux)}
+
+	go startTestingServer(lis, srv, t)
+}
+
+func startTestingServer(lis net.Listener, srv *http.Server, t *testing.T) {
+	if srv == nil {
+		t.Errorf("srv is nil. Could not listen")
+		return
+	}
+
+	go func() {
+		if err := srv.Serve(lis); err != nil {
+			t.Errorf("couldn't start server: %v", err)
+		}
+	}()
+}
+
 func TestJWTSignatureVerificationSucceeds(t *testing.T) {
 func TestJWTSignatureVerificationSucceeds(t *testing.T) {
 	// testBase(t, 1000, 200)
 	// testBase(t, 1000, 200)
 }
 }