diff --git a/tes/utils.go b/tes/utils.go index 3ffc8655..d6be4459 100644 --- a/tes/utils.go +++ b/tes/utils.go @@ -33,7 +33,6 @@ func Base64Encode(t *Task) (string, error) { if err != nil { return "", err } - fmt.Println(str) str = base64.StdEncoding.EncodeToString([]byte(str)) return str, nil } diff --git a/tes/utils_test.go b/tes/utils_test.go index 3f2d7e15..c3381d3d 100644 --- a/tes/utils_test.go +++ b/tes/utils_test.go @@ -16,16 +16,23 @@ func TestBase64Encode(t *testing.T) { }, } - expected := "ewogICJpZCI6ICJ0YXNrMSIsCiAgImV4ZWN1dG9ycyI6IFsKICAgIHsKICAgICAgImltYWdlIjogImFscGluZSIsCiAgICAgICJjb21tYW5kIjogWwogICAgICAgICJlY2hvIiwKICAgICAgICAiaGVsbG8gd29ybGQiCiAgICAgIF0KICAgIH0KICBdCn0=" + // Protojson may (and may not) add extra whitespace between labels and values. + // Therefore there are two possible scenarios when the test checks against specific BASE64 value(s). + // More info: https://github.com/golang/protobuf/issues/1082 + expected1 := "ewogICJpZCI6ICJ0YXNrMSIsCiAgImV4ZWN1dG9ycyI6IFsKICAgIHsKICAgICAgImltYWdlIjogImFscGluZSIsCiAgICAgICJjb21tYW5kIjogWwogICAgICAgICJlY2hvIiwKICAgICAgICAiaGVsbG8gd29ybGQiCiAgICAgIF0KICAgIH0KICBdCn0=" + expected2 := "ewogICJpZCI6ICAidGFzazEiLAogICJleGVjdXRvcnMiOiAgWwogICAgewogICAgICAiaW1hZ2UiOiAgImFscGluZSIsCiAgICAgICJjb21tYW5kIjogIFsKICAgICAgICAiZWNobyIsCiAgICAgICAgImhlbGxvIHdvcmxkIgogICAgICBdCiAgICB9CiAgXQp9" encoded, err := Base64Encode(task) if err != nil { t.Fatal(err) } - if encoded != expected { - t.Logf("expected: %+v", expected) - t.Logf("actual: %+v", encoded) + if encoded != expected1 && encoded != expected2 { + str, err := MarshalToString(task) + t.Logf("Source JSON-string: %+v (error: %+v)", str, err) + t.Logf("actual: %+v", encoded) + t.Logf("expected1: %+v", expected1) + t.Logf("expected2: %+v", expected2) t.Fatal("unexpected value returned from Base64Encode") }