github.com/apache/skywalking-eyes@v0.6.0/pkg/header/config_test.go (about) 1 // Licensed to the Apache Software Foundation (ASF) under one 2 // or more contributor license agreements. See the NOTICE file 3 // distributed with this work for additional information 4 // regarding copyright ownership. The ASF licenses this file 5 // to you under the Apache License, Version 2.0 (the 6 // "License"); you may not use this file except in compliance 7 // with the License. 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 header 19 20 import ( 21 "fmt" 22 "strconv" 23 "testing" 24 "time" 25 ) 26 27 func TestGetLicenseContent(t *testing.T) { 28 { 29 header := ConfigHeader{ 30 License: LicenseConfig{ 31 SpdxID: "Apache-2.0", 32 CopyrightOwner: "Foo", 33 SoftwareName: "Bar", 34 }, 35 } 36 expectContent := fmt.Sprintf( 37 `Copyright %s Foo 38 39 Licensed under the Apache License, Version 2.0 (the "License"); 40 you may not use this file except in compliance with the License. 41 You may obtain a copy of the License at 42 43 http://www.apache.org/licenses/LICENSE-2.0 44 45 Unless required by applicable law or agreed to in writing, software 46 distributed under the License is distributed on an "AS IS" BASIS, 47 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 48 See the License for the specific language governing permissions and 49 limitations under the License. 50 `, strconv.Itoa(time.Now().Year())) 51 actualContent := header.GetLicenseContent() 52 if actualContent != expectContent { 53 t.Errorf("GetLicenseContent() result has failure:\n\n%s\n\nWanted:\n\n%s\n", expectContent, actualContent) 54 } 55 } 56 57 { 58 header := ConfigHeader{ 59 License: LicenseConfig{ 60 SpdxID: "Apache-2.0", 61 CopyrightOwner: "Apache Software Foundation", 62 SoftwareName: "Bar", 63 }, 64 } 65 expectContent := `Licensed to the Apache Software Foundation (ASF) under one 66 or more contributor license agreements. See the NOTICE file 67 distributed with this work for additional information 68 regarding copyright ownership. The ASF licenses this file 69 to you under the Apache License, Version 2.0 (the 70 "License"); you may not use this file except in compliance 71 with the License. You may obtain a copy of the License at 72 73 http://www.apache.org/licenses/LICENSE-2.0 74 75 Unless required by applicable law or agreed to in writing, 76 software distributed under the License is distributed on an 77 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 78 KIND, either express or implied. See the License for the 79 specific language governing permissions and limitations 80 under the License. 81 ` 82 actualContent := header.GetLicenseContent() 83 if actualContent != expectContent { 84 t.Errorf("GetLicenseContent() result has failure:\n\n%s\n\nWanted:\n\n%s\n", expectContent, actualContent) 85 } 86 } 87 88 { 89 header := ConfigHeader{ 90 License: LicenseConfig{ 91 SpdxID: "MulanPSL-2.0", 92 CopyrightOwner: "Foo", 93 SoftwareName: "Bar", 94 }, 95 } 96 expectContent := fmt.Sprintf( 97 `Copyright (c) %s Foo 98 Bar is licensed under Mulan PSL v2. 99 You can use this software according to the terms and conditions of the Mulan PSL v2. 100 You may obtain a copy of Mulan PSL v2 at: 101 http://license.coscl.org.cn/MulanPSL2 102 THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 103 EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 104 MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 105 See the Mulan PSL v2 for more details. 106 `, strconv.Itoa(time.Now().Year())) 107 actualContent := header.GetLicenseContent() 108 if actualContent != expectContent { 109 t.Errorf("GetLicenseContent() result has failure:\n\n%s\n\nWanted:\n\n%s\n", expectContent, actualContent) 110 } 111 } 112 }