Skip to content

Tests failing with Go 1.27 due to hard-coded gzip bytes #709

Description

@prattmic

Various tests in this repo fail when running with the upcoming Go 1.27.

There is no 1.27 release candidate yet, but you can test with golang.org/dl/gotip:

$ go install golang.org/dl/gotip@latest
$ gotip download
$ gotip test ./...
ok      github.com/coreos/butane/base/util      0.170s                                                                                                                                                                                                         
ok      github.com/coreos/butane/base/v0_1      0.020s                                                                                                                                                                                                         
--- FAIL: TestTranslateFile (0.05s)                                                                                                                                                                                                                            
    --- FAIL: TestTranslateFile/translate_8 (0.05s)                                                                                                                                                                                                            
        translate_test.go:595:                                                                                                                                                                                                                                 
                Error Trace:    /tmp/butane/base/v0_2/translate_test.go:595                                                                                                                                                                                    
                Error:          Not equal:                                                                                                                                                                                                                     
                                expected: types.File{Node:types.Node{Group:types.NodeGroup{ID:(*int)(nil), Name:(*string)(nil)}, Overwrite:(*bool)(nil), Path:"/foo", User:types.NodeUser{ID:(*int)(nil), Name:(*string)(nil)}}, FileEmbedded1:types.FileEmbedd
ed1{Append:[]types.Resource{types.Resource{Compression:(*string)(0x3fe3ea226d00), HTTPHeaders:types.HTTPHeaders(nil), Source:(*string)(0x3fe3ea226cf0), Verification:types.Verification{Hash:(*string)(nil)}}, types.Resource{Compression:(*string)(0x3fe3ea226
d20), HTTPHeaders:types.HTTPHeaders(nil), Source:(*string)(0x3fe3ea226d10), Verification:types.Verification{Hash:(*string)(nil)}}, types.Resource{Compression:(*string)(0x3fe3ea226d40), HTTPHeaders:types.HTTPHeaders(nil), Source:(*string)(0x3fe3ea226d30), 
Verification:types.Verification{Hash:(*string)(nil)}}, types.Resource{Compression:(*string)(0x3fe3ea226d60), HTTPHeaders:types.HTTPHeaders(nil), Source:(*string)(0x3fe3ea226d50), Verification:types.Verification{Hash:(*string)(nil)}}, types.Resource{Compre
ssion:(*string)(0x3fe3ea226d80), HTTPHeaders:types.HTTPHeaders(nil), Source:(*string)(0x3fe3ea226d70), Verification:types.Verification{Hash:(*string)(nil)}}}, Contents:types.Resource{Compression:(*string)(0x3fe3ea226ce0), HTTPHeaders:types.HTTPHeaders(nil
), Source:(*string)(0x3fe3ea226cd0), Verification:types.Verification{Hash:(*string)(nil)}}, Mode:(*int)(nil)}}
                                actual  : types.File{Node:types.Node{Group:types.NodeGroup{ID:(*int)(nil), Name:(*string)(nil)}, Overwrite:(*bool)(nil), Path:"/foo", User:types.NodeUser{ID:(*int)(nil), Name:(*string)(nil)}}, FileEmbedded1:types.FileEmbedd
ed1{Append:[]types.Resource{types.Resource{Compression:(*string)(0x3fe3ea226340), HTTPHeaders:types.HTTPHeaders(nil), Source:(*string)(0x3fe3ea42bec0), Verification:types.Verification{Hash:(*string)(nil)}}, types.Resource{Compression:(*string)(0x3fe3ea226
5b0), HTTPHeaders:types.HTTPHeaders(nil), Source:(*string)(0x3fe3ea2265a0), Verification:types.Verification{Hash:(*string)(nil)}}, types.Resource{Compression:(*string)(0x3fe3ea42a010), HTTPHeaders:types.HTTPHeaders(nil), Source:(*string)(0x3fe3ea42a000), 
Verification:types.Verification{Hash:(*string)(nil)}}, types.Resource{Compression:(*string)(0x3fe3ea42a170), HTTPHeaders:types.HTTPHeaders(nil), Source:(*string)(0x3fe3ea42a200), Verification:types.Verification{Hash:(*string)(nil)}}, types.Resource{Compre
ssion:(*string)(0x3fe3ea42a340), HTTPHeaders:types.HTTPHeaders(nil), Source:(*string)(0x3fe3ea42a3d0), Verification:types.Verification{Hash:(*string)(nil)}}}, Contents:types.Resource{Compression:(*string)(0x3fe3ea42a020), HTTPHeaders:types.HTTPHeaders(nil
), Source:(*string)(0x3fe3ea42a570), Verification:types.Verification{Hash:(*string)(nil)}}, Mode:(*int)(nil)}}
                                
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -18,3 +18,3 @@
                                     HTTPHeaders: (types.HTTPHeaders) <nil>,
                                -    Source: (*string)((len=49) "data:;base64,H4sIAAAAAAAC/6oajAAQAAD//5tA8d+VAAAA"),
                                +    Source: (*string)((len=45) "data:;base64,H4sIAAAAAAAC/6oajAAwAJtA8d+VAAAA"),
                                     Verification: (types.Verification) {
                                @@ -59,3 +59,3 @@
                                    HTTPHeaders: (types.HTTPHeaders) <nil>,
                                -   Source: (*string)((len=49) "data:;base64,H4sIAAAAAAAC/6oajAAQAAD//5tA8d+VAAAA"),
                                +   Source: (*string)((len=45) "data:;base64,H4sIAAAAAAAC/6oajAAwAJtA8d+VAAAA"),
                                    Verification: (types.Verification) {
                Test:           TestTranslateFile/translate_8
                Messages:       translation mismatch
<more, similar failures>

The various translate tests include output fields containing compressed data. Currently the test hard-codes the expected base64-encoded compressed bytes.

Upstream Go CL https://go.dev/cl/707355 improves the performance of compress/flate (used by compress/gzip), which results in different compressed bytes. The exact byte output of compress/gzip is not guaranteed to remain stable and should be considered an implementation detail. Only the uncompressed content is stable.

When running with this CL, these tests fail due to the fragile dependency on the exact compressed bytes.

Since this is a test-only issue, one easy fix is to compress the expected output on the fly at runtime. Something like:

func gzipURI(t *testing.T, s string) string {
      var buf bytes.Buffer
      bw := base64.NewEncoder(base64.StdEncoding, &buf)
      gw, err := gzip.NewWriterLevel(bw, gzip.BestCompression)
      if err != nil {
              t.Fatalf("Error creating gzip writer: %v", err)
      }
      if _, err := gw.Write([]byte(s)); err != nil {
              t.Fatalf("Error writing string for compression: %v", err)
      }
      if err := gw.Close(); err != nil {
              t.Fatalf("Error closing gzip writer: %v", err)
      }
      if err := bw.Close(); err != nil {
              t.Fatalf("Error closing base64 writer: %v", err)
      }
      return "data:;base64," + buf.String()
}

func TestTranslateFile(t *testing.T) {
      zzz := "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
      zzz_gz := gzipURI(t, zzz)
...

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions