github.com/bartle-stripe/trillian@v1.2.1/storage/tools/dump_tree/dumplib/nochange_test.go (about)

     1  // Copyright 2017 Google Inc. All Rights Reserved.
     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  package dumplib
    16  
    17  import (
    18  	"io/ioutil"
    19  	"strings"
    20  	"testing"
    21  
    22  	_ "github.com/google/trillian/crypto/keys/der/proto"
    23  )
    24  
    25  // TestDBFormatNoChange ensures that the prefix, suffix, and protos stored in the database do not change.
    26  // This test compares the output from dump_tree against a previously saved output.
    27  func TestDBFormatNoChange(t *testing.T) {
    28  	for _, tc := range []struct {
    29  		desc string
    30  		file string
    31  		opts Options
    32  	}{
    33  		{
    34  			desc: "tree_size: 96",
    35  			file: "../../../../testdata/dump_tree_output_96",
    36  			opts: Options{
    37  				96, 50,
    38  				"Leaf %d",
    39  				true, false, false, false, false, true, false, false,
    40  			},
    41  		},
    42  		{
    43  			desc: "tree_size: 871",
    44  			file: "../../../../testdata/dump_tree_output_871",
    45  			opts: Options{
    46  				871, 50,
    47  				"Leaf %d",
    48  				true, false, false, false, false, true, false, false,
    49  			},
    50  		},
    51  		{
    52  			desc: "tree_size: 1000",
    53  			file: "../../../../testdata/dump_tree_output_1000",
    54  			opts: Options{
    55  				1000, 50,
    56  				"Leaf %d",
    57  				true, false, false, false, false, true, false, false,
    58  			},
    59  		},
    60  		{
    61  			desc: "tree_size: 1024",
    62  			file: "../../../../testdata/dump_tree_output_1024",
    63  			opts: Options{
    64  				1024, 50,
    65  				"Leaf %d",
    66  				true, false, false, false, false, true, false, false,
    67  			},
    68  		},
    69  	} {
    70  		out := Main(tc.opts)
    71  		saved, err := ioutil.ReadFile(tc.file)
    72  		if err != nil {
    73  			t.Fatalf("ReadFile(%v): %v", tc.file, err)
    74  		}
    75  
    76  		savedS := strings.Split(string(saved), "\n")
    77  		outS := strings.Split(out, "\n")
    78  		for i := range savedS {
    79  			if got, want := savedS[i], outS[i]; got != want {
    80  				t.Errorf("%v dump_tree line %3v %v, want %v", tc.desc, i, got, want)
    81  			}
    82  		}
    83  		if got, want := len(savedS), len(outS); got != want {
    84  			t.Errorf("%v dump_tree %v lines, want %v", tc.desc, got, want)
    85  		}
    86  	}
    87  }