github.com/thanos-io/thanos@v0.32.5/cmd/thanos/tools_test.go (about) 1 // Copyright (c) The Thanos Authors. 2 // Licensed under the Apache License 2.0. 3 4 package main 5 6 import ( 7 "testing" 8 9 "github.com/go-kit/log" 10 11 "github.com/efficientgo/core/testutil" 12 ) 13 14 func Test_CheckRules(t *testing.T) { 15 validFiles := []string{ 16 "./testdata/rules-files/valid.yaml", 17 } 18 19 invalidFiles := [][]string{ 20 {"./testdata/rules-files/non-existing-file.yaml"}, 21 {"./testdata/rules-files/invalid-yaml-format.yaml"}, 22 {"./testdata/rules-files/invalid-rules-data.yaml"}, 23 {"./testdata/rules-files/invalid-unknown-field.yaml"}, 24 } 25 26 logger := log.NewNopLogger() 27 testutil.Ok(t, checkRulesFiles(logger, &validFiles)) 28 29 for _, fn := range invalidFiles { 30 testutil.NotOk(t, checkRulesFiles(logger, &fn), "expected err for file %s", fn) 31 } 32 } 33 34 func Test_CheckRules_Glob(t *testing.T) { 35 // regex path 36 files := &[]string{"./testdata/rules-files/valid*.yaml"} 37 logger := log.NewNopLogger() 38 testutil.Ok(t, checkRulesFiles(logger, files)) 39 40 // direct path 41 files = &[]string{"./testdata/rules-files/valid.yaml"} 42 testutil.Ok(t, checkRulesFiles(logger, files)) 43 44 // invalid path 45 files = &[]string{"./testdata/rules-files/*.yamlaaa"} 46 testutil.NotOk(t, checkRulesFiles(logger, files), "expected err for file %s", files) 47 }