github.com/oam-dev/kubevela@v1.9.11/pkg/addon/memory_reader_test.go (about)

     1  /*
     2  Copyright 2021 The KubeVela Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package addon
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/stretchr/testify/assert"
    23  	"helm.sh/helm/v3/pkg/chart/loader"
    24  )
    25  
    26  var files = []*loader.BufferedFile{
    27  	{
    28  		Name: "metadata.yaml",
    29  		Data: []byte(`name: test-helm-addon
    30  version: 1.0.0
    31  description: This is a addon for test when install addon from helm repo
    32  icon: https://www.terraform.io/assets/images/logo-text-8c3ba8a6.svg
    33  url: https://terraform.io/
    34  
    35  tags: []
    36  
    37  deployTo:
    38    control_plane: true
    39    runtime_cluster: false
    40  
    41  dependencies: []
    42  
    43  invisible: false`),
    44  	},
    45  	{
    46  		Name: "/resources/parameter.cue",
    47  		Data: []byte(`parameter: {
    48  	// test wrong parameter
    49  	example: *"default"
    50  }`),
    51  	},
    52  }
    53  
    54  func TestMemoryReader(t *testing.T) {
    55  	m := MemoryReader{
    56  		Name:  "fluxcd",
    57  		Files: files,
    58  	}
    59  
    60  	meta, err := m.ListAddonMeta()
    61  	assert.NoError(t, err)
    62  	assert.Equal(t, len(meta["fluxcd"].Items), 2)
    63  
    64  	metaFile, err := m.ReadFile("metadata.yaml")
    65  	assert.NoError(t, err)
    66  	assert.NotEmpty(t, metaFile)
    67  
    68  	parameterData, err := m.ReadFile("/resources/parameter.cue")
    69  	assert.NoError(t, err)
    70  	assert.NotEmpty(t, parameterData)
    71  }