go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/server/portal/internal/assets/assets_test.go (about)

     1  // Copyright 2023 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // AUTOGENERATED. DO NOT EDIT.
    16  
    17  // This file is generated by go.chromium.org/luci/tools/cmd/assets.
    18  //
    19  // It contains tests that ensure that assets embedded into the binary are
    20  // identical to files on disk.
    21  
    22  package assets
    23  
    24  import (
    25  	"go/build"
    26  	"os"
    27  	"path/filepath"
    28  	"testing"
    29  )
    30  
    31  func TestAssets(t *testing.T) {
    32  	t.Parallel()
    33  
    34  	pkg, err := build.ImportDir(".", build.FindOnly)
    35  	if err != nil {
    36  		t.Fatalf("can't load package: %s", err)
    37  	}
    38  
    39  	fail := false
    40  	for name := range Assets() {
    41  		GetAsset(name) // for code coverage
    42  		path := filepath.Join(pkg.Dir, filepath.FromSlash(name))
    43  		blob, err := os.ReadFile(path)
    44  		if err != nil {
    45  			t.Errorf("can't read file with assets %q (%s) - %s", name, path, err)
    46  			fail = true
    47  		} else if string(blob) != GetAssetString(name) {
    48  			t.Errorf("embedded asset %q is out of date", name)
    49  			fail = true
    50  		}
    51  	}
    52  
    53  	if fail {
    54  		t.Fatalf("run 'go generate' to update assets.gen.go")
    55  	}
    56  }