github.com/zntrio/harp/v2@v2.0.9/pkg/template/values/hcl1/hcl1_test.go (about) 1 // Licensed to Elasticsearch B.V. under one or more contributor 2 // license agreements. See the NOTICE file distributed with 3 // this work for additional information regarding copyright 4 // ownership. Elasticsearch B.V. licenses this file to you under 5 // the Apache License, Version 2.0 (the "License"); you may 6 // not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, 12 // software distributed under the License is distributed on an 13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 // KIND, either express or implied. See the License for the 15 // specific language governing permissions and limitations 16 // under the License. 17 18 package hcl1 19 20 import ( 21 "testing" 22 ) 23 24 const sample = `provider "google" { 25 version = "2.5.0" 26 project = "instrumenta" 27 region = "europe-west2" 28 29 30 } 31 32 resource "google_container_cluster" "primary" { 33 name = "my-gke-cluster" 34 location = "us-central1" 35 36 # We can't create a cluster with no node pool defined, but we want to only use 37 # separately managed node pools. So we create the smallest possible default 38 # node pool and immediately delete it. 39 remove_default_node_pool = true 40 initial_node_count = 1 41 42 # Setting an empty username and password explicitly disables basic auth 43 master_auth { 44 username = "" 45 password = "" 46 } 47 } 48 49 resource "google_container_node_pool" "primary_preemptible_nodes" { 50 name = "my-node-pool" 51 location = "us-central1" 52 cluster = "${google_container_cluster.primary.name}" 53 node_count = 1 54 55 node_config { 56 preemptible = true 57 machine_type = "n1-standard-1" 58 59 metadata = { 60 disable-legacy-endpoints = "true" 61 } 62 63 oauth_scopes = [ 64 "https://www.googleapis.com/auth/logging.write", 65 "https://www.googleapis.com/auth/monitoring", 66 ] 67 } 68 } 69 70 # The following outputs allow authentication and connectivity to the GKE Cluster 71 # by using certificate-based authentication. 72 output "client_certificate" { 73 value = "${google_container_cluster.primary.master_auth.0.client_certificate}" 74 } 75 76 output "client_key" { 77 value = "${google_container_cluster.primary.master_auth.0.client_key}" 78 } 79 80 output "cluster_ca_certificate" { 81 value = "${google_container_cluster.primary.master_auth.0.cluster_ca_certificate}" 82 }` 83 84 func TestHcl1Parser(t *testing.T) { 85 var input interface{} 86 parser := &Parser{} 87 sampleFileBytes := []byte(sample) 88 if err := parser.Unmarshal(sampleFileBytes, &input); err != nil { 89 t.Fatalf("parser should not have thrown an error: %v", err) 90 } 91 92 if input == nil { 93 t.Error("there should be information parsed but its nil") 94 } 95 96 inputMap := input.(map[string]interface{}) 97 if len(inputMap["resource"].([]map[string]interface{})) <= 0 { 98 t.Error("there should be resources defined in the parsed file, but none found") 99 } 100 }