github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/internal/fs/fs_test.go (about)

     1  // Copyright (c) 2022, R.I. Pienaar and the Choria Project contributors
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package fs
     6  
     7  import (
     8  	"encoding/json"
     9  	"io/fs"
    10  	"os"
    11  	"path/filepath"
    12  	"testing"
    13  
    14  	. "github.com/onsi/ginkgo/v2"
    15  	. "github.com/onsi/gomega"
    16  )
    17  
    18  func TestFS(t *testing.T) {
    19  	RegisterFailHandler(Fail)
    20  	RunSpecs(t, "Internal/FS")
    21  }
    22  
    23  var _ = Describe("FS", func() {
    24  	Describe("JSON Files", func() {
    25  		It("Should have valid JSON files", func() {
    26  			err := filepath.Walk(".", func(path string, info fs.FileInfo, err error) error {
    27  				if err != nil {
    28  					return err
    29  				}
    30  
    31  				if filepath.Ext(path) != ".json" {
    32  					return nil
    33  				}
    34  
    35  				d := map[string]any{}
    36  				jd, err := os.ReadFile(path)
    37  				if err != nil {
    38  					return err
    39  				}
    40  
    41  				return json.Unmarshal(jd, &d)
    42  			})
    43  			Expect(err).ToNot(HaveOccurred())
    44  		})
    45  	})
    46  })