Skip to content

Commit 2eb1f34

Browse files
committed
Split unit test
1 parent 3ea593d commit 2eb1f34

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

otlpinf/otlpinf_test.go

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,50 @@ func TestOtlpinfCreateDeletePolicy(t *testing.T) {
236236
t.Errorf(ERROR_MSG, resp.StatusCode, http.StatusOK)
237237
}
238238

239+
otlp.Stop(ctx)
240+
}
241+
242+
func TestOtlpinfCreateInvalidPolicy(t *testing.T) {
243+
// Arrange
244+
logger := zaptest.NewLogger(t)
245+
cfg := config.Config{
246+
Debug: true,
247+
ServerHost: TEST_HOST,
248+
ServerPort: 55682,
249+
}
250+
251+
SERVER := fmt.Sprintf("http://%s:%v", cfg.ServerHost, cfg.ServerPort)
252+
253+
// Act and Assert
254+
otlp, err := New(logger, &cfg)
255+
if err != nil {
256+
t.Errorf("New() error = %v", err)
257+
}
258+
259+
ctx, cancel := context.WithCancel(context.Background())
260+
err = otlp.Start(ctx, cancel)
261+
262+
if err != nil {
263+
t.Errorf("Start() error = %v", err)
264+
}
265+
266+
time.Sleep(100 * time.Millisecond)
267+
268+
policyName := "policy_test"
269+
239270
//Act try to insert policy without config
240-
data[policyName] = map[string]interface{}{
241-
"feature_gates": []string{"all"},
271+
data := map[string]interface{}{
272+
policyName: map[string]interface{}{
273+
"feature_gates": []string{"all"},
274+
},
242275
}
276+
var buf bytes.Buffer
243277
err = yaml.NewEncoder(&buf).Encode(data)
244278
if err != nil {
245279
t.Errorf(YAML_ERR_MSG, err)
246280
}
247281

248-
resp, err = http.Post(SERVER+POLICIES_API, HTTP_YAML_CONTENT, &buf)
282+
resp, err := http.Post(SERVER+POLICIES_API, HTTP_YAML_CONTENT, &buf)
249283
if err != nil {
250284
t.Errorf(POST_ERR_MSG, err)
251285
}

0 commit comments

Comments
 (0)