Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use go1.18 to build gitea #19099

Merged
merged 14 commits into from Mar 16, 2022
56 changes: 56 additions & 0 deletions modules/util/net_test.go
@@ -0,0 +1,56 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package util

import (
"net"
"testing"

"github.com/stretchr/testify/assert"
)

func TestIsIPPPrivate(t *testing.T) {
cases := []struct {
ip string
isPrivate bool
}{
// case 0
{
ip: "127.0.0.1",
isPrivate: true,
},
// case 1
{
ip: "127.1.2.3",
isPrivate: true,
},
// case 2
{
ip: "10.255.255.0",
isPrivate: true,
},
// case 3
{
ip: "8.8.8.8",
isPrivate: false,
},
// case 4
{
ip: "::1",
isPrivate: true,
},
// case 4
{
ip: "2a12:7c40::f00d",
isPrivate: false,
},
}

for n, c := range cases {
i, _ := net.ParseIP(c.ip)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we already should include go1.18 code, even for tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is go1.17 code: https://cs.opensource.google/go/go/+/refs/tags/go1.17:src/net/ip.go;l=704

Edit: This just adds tests for logic we already had

p := IsIPPrivate(i)
assert.Equal(t, c.isPrivate, p, "case %d: should be equal", n)
}
}